#!/usr/bin/bash

min=30
max=70
step=5

MIN=0
MAX=100


if [[ "" == $1 ]] ; then

  echo flags: inc dec min max
  echo keys: + <value> - <value> = <num> 

  echo "Usage:
  sway-tools-light [FLAG]
  sway-tools-light [KEY] <value>

  Try 'sway-tools-light --help' for more information."
  exit 1
if [[ '--help' == $1 || "-h" == $1 ]] ; then
  echo "keys:  inc  dec  + <value>  - <value>  = <num> 

Usage:
  sway-tools-light dec     light -= $step F11
  sway-tools-light inc     light += $step F12
  
  sway-tools-light min     light = $min
  sway-tools-light max     light = $max

  # sway-tools-light mute    F9

  sway-tools-light - <value>   light = $sum
  sway-tools-light + <value>   light = $sum
  
  sway-tools-light = <num>  $MIN < <num> > $MAX
"
  exit 1
else
  key=$1
  num=$2
fi

echo $n

if [[ inc == $key || dec == $key ]] ; then
  sway-tools-light $key $step

elif [[ $key == min ]] ; then
  sway-tools-light = $min
elif [[ $key == max ]] ; then
  sway-tools-light = $max

elif [[ - == $key || + == $key || = == $key ]] ; then
  xbackground $key $num

fi

xbackground $key $num








if [[ $1 == "" ]] ; then
  echo "keys: inc dec
  
  sway-tools-volume inc     sway-tools-volume + $step
  sway-tools-volume dec     sway-tools-volume - $step
  
  sway-tools-volume max     sway-tools-volume = $max
  sway-tools-volume min     sway-tools-volume = $min

  sway-tools-volume mute    sway-tools-volume mute

  sway-tools-volume - <value>   > $MIN
  sway-tools-volume + <value>   < $MAX
  sway-tools-volume = <n>  $MIN < <n> > $MAX
"
  exit 1
else
  char=$1
  num=$2
fi

if [[ "get" == $char ]] ; then
  return 0
elif [[ "inc" == $char ]] ; then
  pactl set-sink-volume @DEFAULT_SINK@ +$step%
elif [[ "dec" == $char ]] ; then
  pactl set-sink-volume @DEFAULT_SINK@ -$step%
elif [[ "mute" == $char ]] ; then
  pactl set-sink-mute @DEFAULT_SINK@ toggle
elif [[ "min" == $char ]] ; then
  pactl set-sink-volume @DEFAULT_SINK@ $min%
elif [[ "max" == $char ]] ; then
  pactl set-sink-volume @DEFAULT_SINK@ $max%
elif [[ "+" == $char ]] ; then
  sum=$(( `get volume` + $num))
   
  if [[ $sum > $MAX ]] ; then
    sum=$MIN
  fi
  
  pactl set-sink-volume @DEFAULT_SINK@ +$num%
  # pactl set-sink-volume @DEFAULT_SINK@ $sum%
elif [[ "-" == $char ]] ; then
  sum=$(( `get volume` - $num)) 

  if [[ $sum < $MIN ]] ; then
    sum=$MIN
  fi
  
  pactl set-sink-volume @DEFAULT_SINK@ -$num%
elif [[ "=" == $char ]] ; then
  # IF [[ $num > $MAX ]] ; THEN
  #	 num=$MAX
  # FLIF [[ $num < $MIN ]] ; THEN
  #	 num=$MIN
  # FI
  
  pactl set-sink-volume @DEFAULT_SINK@ $num%
fi

